import json#模块的导入
#制定高维数据
lst=[
    {'name':'梅旺阳','age':'18','grade':100},
    {'name':'魏清林','age':'18','grade':100},
    {'name':'梅翔','age':'17','grade':100},
]
#
s=json.dumps(lst,ensure_ascii=False,indent=4)#ensure_ascii正常显示中文，indent增加数据的缩进，json格式的字符串更具有可读性
print(type(s),s)#编码lst-->str
#解码
lst2=json.loads(s)
print(type(lst2),lst2)
#编码到文件中
with open('handsome_man.text','w',encoding='utf-8') as file:
    json.dump(lst,file,ensure_ascii=False,indent=1)
#解码到程序当中
with open('handsome_man.text','r',encoding='utf-8') as file:
    lst3=json.load(file)
    print(type(lst3),lst3)




